package com.gmail.blackdog1987.carcare.network.response.handler;

import com.gmail.blackdog1987.carcare.util.LogUtil;
import com.loopj.android.http.JsonHttpResponseHandler;

/**
 * BaseResponseHandler
 * 
 * @author 董国超
 * @date 2013-5-29
 */
public abstract class BaseResponseHandler extends JsonHttpResponseHandler implements IResponseHandler {
	/**
	 * @param e
	 * @return true 正常 false 异常
	 */
	public boolean checkConn(Throwable e) {
		if (e instanceof org.apache.http.conn.HttpHostConnectException) {
			LogUtil.e("BaseResponseHandler", "HttpHostConnectException.");
			return false;
		} else if (e instanceof java.net.SocketTimeoutException) {
			LogUtil.e("BaseResponseHandler", "SocketTimeoutException.");
			return false;
		} else if (e instanceof java.net.SocketException) {
			LogUtil.e("BaseResponseHandler", "SocketException.");
			return false;
		} else if(e instanceof java.net.UnknownHostException){
			LogUtil.e("BaseResponseHandler", "UnknownHostException.");
			return false;
		} else if (e instanceof org.apache.http.conn.ConnectTimeoutException){
			LogUtil.e("BaseResponseHandler", "ConnectTimeoutException.");
			return false;
		}
		return true;
	}
	
	/**
	 * 验证是否是WLAN登录信息
	 * @param responseObj
	 * @return
	 */
	public boolean checkWLAN(Object responseObj){
		if(!(responseObj instanceof String)){
			return false;
		}
		if(((String)responseObj).startsWith("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">")){
			return true;
		}
		return false;
	}
}
